﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Test4
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("请输入二维数组的行数和列数：");
            string[] rowAndCol = Console.ReadLine().Split(new char[] {' '}[0]);
            int m = Int32.Parse(rowAndCol[0]);
            int n = Int32.Parse(rowAndCol[1]);
            Console.WriteLine("请输入二维数组的值：");
            int[,] matrix = new int[m, n];
            for (int i = 0; i < m; i++)
            {
                string[] tmp = Console.ReadLine().Split(new char[] { ' ' }[0]);
                for (int j = 0; j < n; j++)
                {
                    matrix[i, j] = int.Parse(tmp[j]);//将分割后的字符付给二维数组每个元素
                }
            }
            if (judgeMatrix(matrix))
            {
                Console.WriteLine("该矩阵是一个托普利茨矩阵。");
            }
            else
            {
                Console.WriteLine("该矩阵不是一个托普利茨矩阵。");
            }
            Console.ReadKey();
        }
        public static bool judgeMatrix(int[,] matrix)
        {
            int m = matrix.GetLength(0);
            int n = matrix.GetLength(1);
            for (int i = 0; i < m - 1; ++i)
            {
                for (int j = 0; j < n - 1; ++j)
                {
                    if (matrix[i, j] != matrix[i + 1, j + 1])
                    {
                        return false;
                    }
                }
            }
            return true;
        }
    }
}
